// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Vector4ConverterTest.cs" company="Microsoft Corporation">
// The MIT License (MIT)
// 
// Copyright (c) 2014, Microsoft Corporation
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace Test.Robotics.Numerics
{
    using System;
    using System.ComponentModel;
    using Microsoft.Robotics.Numerics;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    /// <summary>
    /// Unit tests for the Vector4Converter class
    /// </summary>
    [TestClass]
    public class Vector4ConverterTest
    {
        /// <summary>
        /// Test the conversion from a string to a vector
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void Vector4ConverterTestConvertFromString()
        {
            Vector4 vector = new Vector4(0, 0, 0, 0);
            vector = (Vector4)TypeDescriptor.GetConverter(typeof(Vector4)).ConvertFrom("1.0,2.0,3.0,4.0");
            Assert.IsTrue(
                vector.X == 1.0
                && vector.Y == 2.0
                && vector.Z == 3.0
                && vector.W == 4.0,
                "Vector4Converter ConvertFromString Test Failed");
        }

        /// <summary>
        /// Test the conversion from a vector to a string
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void Vector4ConverterTestConvertToString()
        {
            Vector4 vector = new Vector4(1, 2, 3, 4);
            string mystring = (string)TypeDescriptor.GetConverter(typeof(Vector4)).ConvertTo(vector, typeof(string));
            Assert.IsTrue(mystring == "1.00, 2.00, 3.00, 4.00", "Vector4Converter ConvertToString Test Failed");
        }

        /// <summary>
        /// Test if can convert from string
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void Vector4ConverterTestCanConvert()
        {
            Assert.IsTrue(TypeDescriptor.GetConverter(typeof(Vector4)).CanConvertFrom(typeof(string)), "Vector4Converter ConvertToString Test Failed");
        }

        /// <summary>
        /// Test Get Properties
        /// </summary>
        [Priority(0)]
        [TestMethod]
        [TestCategory("Unit")]
        public void Vector4ConverterTestGetProperties()
        {
            Vector4 vector = new Vector4(1, 2, 3, 4);
            PropertyDescriptorCollection propCollection = TypeDescriptor.GetConverter(typeof(Vector4)).GetProperties(vector);

            Assert.IsTrue(
                propCollection.Contains(propCollection["X"]) == true
                && propCollection.Contains(propCollection["Y"]) == true
                && propCollection.Contains(propCollection["Z"]) == true
                && propCollection.Contains(propCollection["W"]) == true,
                "Vector4Converter GetProperties test failed");
        }
    }
}
